# -*- coding: UTF-8 -*-
"""
@Project ：lufei-learning-city 
@File    ：事务.py
@IDE     ：PyCharm 
@Author  ：于金龙@阿龙的代码在报错
@Date    ：2024/9/26 下午1:57 
"""
import pymysql

conn = pymysql.connect(
    host='localhost',
    port=3306,
    user='root',
    passwd='20020115',
    charset='utf8',
    db='day29'
)
cursor = conn.cursor()

conn.begin()

try:
    cursor.execute("update users set amount=1 where id =1")
    cursor.execute("update users set amount=1 where id =2")
except Exception as e:
    # 回滚
    print("回滚")
    conn.rollback()
else:
    # 提交
    print('提交')
    conn.commit()
cursor.close()
conn.close()
